package io.xxx.mario.config;

import lombok.extern.slf4j.Slf4j;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
public class CuratorConfig {

    @Bean(destroyMethod = "close")
    public CuratorFramework curator(ImadcnProperties properties) {
        CuratorFramework curator = CuratorFrameworkFactory.builder()
                .connectString(properties.getZookeeper().getServers())
                .retryPolicy(new ExponentialBackoffRetry(1000, 3))
                .connectionTimeoutMs(15 * 1000)
                .sessionTimeoutMs(60 * 1000)
                .namespace("mario")
                .build();
        curator.start();
        return curator;
    }
}
